<link href="<?php echo base_url(); ?>public/admin/css/banner.css" rel="stylesheet" type="text/css">
<div class="page-content">
    <div class="page-header position-relative">
        <h1>
            Danh sách thành viên cấm !
        </h1>
    </div>
    <div id="post" ">
        <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
            <div class="row-fluid"><div class="span6"><div id="sample-table-2_length" class="dataTables_length"><label>Hiện thị <select size="1" name="sample-table-2_length" aria-controls="sample-table-2"><option value="10" selected="selected">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select> Thành viên</label></div></div><div class="span6"><div class="dataTables_filter" id="sample-table-2_filter"><label>Tìm kiếm: <input type="text" aria-controls="sample-table-2"></label></div></div></div>
            <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th class="center">
                        <label>
                            <input type="checkbox">
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th>User name</th>
                    <th>Email</th>
                    <th class="hidden-480">Người cấm</th>
                    <th class="hidden-phone">Ngày cấm</th>
                    <th class="hidden-480">Thời gian cấm</th>
                    <th class="hidden-480">Thời gian còn lại</th>
                    <th class="hidden-480">Lý do</th>
                    <th>Tùy chỉnh</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($data as $items) {
                    $id = $items['id'];
                    $time = strtotime($items['createdate']); // Dinh danh ngay cam
                    $time = date('d - m - Y',$time);
                    /* tinh so ngay bi cam
                    * =  (thoi gian het cam - thoi gian bat dau cam) /86400 (so giay trong ngay)
                    */
                    $startTimeStamp = strtotime($items['createdate']); // Ngay bat dau cam
                    $endTimeStamp = strtotime($items['timeban']); // Ngay ket thuc cam
                    $timeDiff = abs($endTimeStamp - $startTimeStamp);
                    $numberDays = $timeDiff / 5184000 -1 ;
                    $numberDays = intval($numberDays);

                    /* Tinh So ngay con lai
                     * =  (thoi gian het cam - thoi gian hien tai) /86400 (so giay trong ngay)
                     * */
                    $currTimeStamp = strtotime(date("Y-m-d H:i:s")); // Ngay hien tai
                    $timeDiffCur = abs($endTimeStamp - $currTimeStamp);
                    $numberDayCur = $timeDiffCur / 5184000 -1;
                    $numberDayCur = intval($numberDayCur);
                    

                    // Neu ngay cam con > 0 va status = true xuat ra tai khoan cam
                    if ($numberDays > 0 && $items['status'] == "true") {
                        echo "<tr class='odd'>";
                        echo "<td class='item'></td>";
                        echo "<td class='item'>$items[UserName]</td>";
                        echo "<td class='item'><a href='http://localhost/e-government/index.php/admin/user_info?idbanning=".$items['userid']."'>$items[Email]</a></td>";
                        echo "<td class='item'>Admin</td>";
                        echo "<td class='item'>$time</td>";
                        if ($numberDays<=30)
                        {
                            echo " <td class='item'>$numberDays Ngày</td>";
                            echo " <td class='item'>$numberDayCur Ngày</td>";
                        }
                        else
                        {
                            echo " <td class='item'>Vĩnh Viễn</td>";
                            echo " <td class='item'>Vĩnh Viễn</td>";
                        }
                        echo " <td class='item'>$items[note]</td>";
                        echo " <td class='item'>
                <select class = 'selectbox'  name='custom' >
                    <option value='delay'> -- </option>
                    <option value = 'banner#" . $items['id'] . "'> Xem/Chỉnh sửa </option>
                    <option value='stop_banning#" . $items['id'] . "' > Ngừng cấm </option>
                </select>
                </td>";
                        echo "</tr>";
                        $numberList=$numberList+1;
                    }
                }
                ?>
                </tbody>

            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    window.onload = function () {
        $(".selectbox").change(function () {
            var str = $(this).val();
            var res = str.split("#");
            if (res[0] == "banner") {
                document.location.href = "http://localhost/e-government/admin/banner?idban="+res[1];
            }
            if(res[0] == "stop_banning")
            {
                $.ajax({
                        type: "GET",
                        url: 'http://egov047.juddy.vn/api/ban/status?id='+res[1]+'&status=false',
                        crossDomain: true,
                        success: function(){
                            window.location.reload();

                        },
                         error: function () {
                             window.location.reload();
                    }
                    });

            }
        });
    }
    $(document).ajaxStop(function () {
        window.location.reload();
    });
</script>